from dataclasses import dataclass
import os, sys, re, codecs, binascii, datetime, pickle

from app.lodger1.lodger import Lodger
from app.lodger1.lodger import LodgerItem
from flask import render_template
from flask import g

from app.lodger1 import bp

def GetLodger():
    if 'lodger' not in g:
        g.lodger = Lodger()
    return g.lodger

@bp.route("/")
def lodgerindex():
    return GetLodger().ShowLodger()

@bp.route("/showform/<int:id>")
def showform(id):
    return GetLodger().ShowForm(id)

@bp.route("/delete/<int:id>")
def deleteitem(id):
    return GetLodger().Delete(id)

@bp.route("/add", methods=['POST'])
def add():
    return GetLodger().Add()

@bp.teardown_request
def teardown_lodger(ctx):
    GetLodger().storage.Store()


@bp.route("/api/", methods=['GET'])
def apilodger():
	return GetLodger().APILodger()

@bp.route("/api/", methods=['POST'])
def apiadd():
	return GetLodger().APIAdd()
	
@bp.route("/api/<int:id>", methods=['GET'])
def apiget(id):
	return GetLodger().APIGet(id)

@bp.route("/api/<int:id>", methods=['PUT'])
def apiset(id):
	return GetLodger().APISet(id)

@bp.route("/api/<int:id>", methods=['DELETE'])
def apidelete(id):
	return GetLodger().APIDelete(id)
